<?php 
/** 
 * This sample service contains functions that illustrate typical
 * service operations. This code is for prototyping only. 
 *  
 *  Authenticate users before allowing them to call these methods. 
 */ 

class EditMethod { 
  var $username = "root"; 
  var $password = "24226448hh"; 
  var $server = "localhost"; 
  var $port = "3306"; 
  var $databasename = "elementClass"; 
 
  
  var $connection; 
  public function __construct() { 
    $this->connection = mysqli_connect( 
                       $this->server,  
                       $this->username,  
                       $this->password, 
                       $this->databasename, 
                       $this->port 
                       ); 
    
    $this->throwExceptionOnError($this->connection); 
  } 

  public function editMethod($item) {
	$stmt = mysqli_prepare($this->connection,
		"CALL editMethod(?, ?, ?, ?, ?)");
	$this->throwExceptionOnError();

	
	mysqli_stmt_bind_param($stmt,'iiiii',$item->id_m,
		$item->idAppChar,
		$item->idTargetState,
		$item->idCaseCategorie,
		$item->idLevImp);
	$this->throwExceptionOnError();

mysqli_stmt_execute($stmt);
	$this->throwExceptionOnError();

	mysqli_stmt_free_result($stmt);
	mysqli_close($this->connection);

  }
  
  
  public function deleteMethod($itemID) {
	$stmt = mysqli_prepare($this->connection,
		"CALL deleteMethod(?)");
	$this->throwExceptionOnError();
	
	mysqli_stmt_bind_param($stmt,'i',$itemID);
	$this->throwExceptionOnError();

	mysqli_stmt_execute($stmt);
	$this->throwExceptionOnError();

	mysqli_stmt_free_result($stmt);
	mysqli_close($this->connection);

  }
  
  public function addMethod($item) {
	$stmt = mysqli_prepare($this->connection,
		"CALL addMethod(?)");
	$this->throwExceptionOnError();

	
	mysqli_stmt_bind_param($stmt,'s',$item);
	$this->throwExceptionOnError();

	mysqli_stmt_execute($stmt);
	$this->throwExceptionOnError();

	mysqli_stmt_free_result($stmt);
	mysqli_close($this->connection);

  }
   public function upMethod($itemID,$item) {
	$stmt = mysqli_prepare($this->connection,
		"CALL upMethod(?,?)");
	$this->throwExceptionOnError();

	
	mysqli_stmt_bind_param($stmt,'is',$itemID,$item);
	$this->throwExceptionOnError();

	mysqli_stmt_execute($stmt);
	$this->throwExceptionOnError();

	mysqli_stmt_free_result($stmt);
	mysqli_close($this->connection);

  }
     public function dropAppChar($itemID_1,$itemID_2) {
	$stmt = mysqli_prepare($this->connection,
		"CALL dropAppChar(?,?)");
	$this->throwExceptionOnError();

	
	mysqli_stmt_bind_param($stmt,'ii',$itemID_1,$itemID_2);
	$this->throwExceptionOnError();

	mysqli_stmt_execute($stmt);
	$this->throwExceptionOnError();

	mysqli_stmt_free_result($stmt);
	mysqli_close($this->connection);

  }
  
  public function dropTarSta($itemID_1,$itemID_2) {
	$stmt = mysqli_prepare($this->connection,
		"CALL dropTarSta(?,?)");
	$this->throwExceptionOnError();

	
	mysqli_stmt_bind_param($stmt,'ii',$itemID_1,$itemID_2);
	$this->throwExceptionOnError();

	mysqli_stmt_execute($stmt);
	$this->throwExceptionOnError();

	mysqli_stmt_free_result($stmt);
	mysqli_close($this->connection);

  }
  
  public function dropCasCat($itemID_1,$itemID_2) {
	$stmt = mysqli_prepare($this->connection,
		"CALL dropCasCat(?,?)");
	$this->throwExceptionOnError();

	
	mysqli_stmt_bind_param($stmt,'ii',$itemID_1,$itemID_2);
	$this->throwExceptionOnError();

	mysqli_stmt_execute($stmt);
	$this->throwExceptionOnError();

	mysqli_stmt_free_result($stmt);
	mysqli_close($this->connection);

  }
  
    public function dropLevImp($itemID_1,$itemID_2) {
	$stmt = mysqli_prepare($this->connection,
		"CALL dropLevImp(?,?)");
	$this->throwExceptionOnError();

	
	mysqli_stmt_bind_param($stmt,'ii',$itemID_1,$itemID_2);
	$this->throwExceptionOnError();

	mysqli_stmt_execute($stmt);
	$this->throwExceptionOnError();

	mysqli_stmt_free_result($stmt);
	mysqli_close($this->connection);

  }
  
  
  public function editInputForm() {
	$stmt = mysqli_prepare($this->connection,
		"select inputform.id_m, 
		inputform.idAppChar,
		inputform.idTarSta,
		inputform.idCasCat,
		inputform.idLevImp from  inputform");
	$this->throwExceptionOnError();

	mysqli_stmt_execute($stmt);
	$this->throwExceptionOnError();
	
	 $rows = array();
      mysqli_stmt_bind_result($stmt, $row->id_m,
	  $row->idAppChar,
	  $row->idTargetState,
	  $row->idCaseCategorie,
	  $row->idLevImp);

      while (mysqli_stmt_fetch($stmt)) {
          $rows[] = $row;
          $row = new stdClass();
          mysqli_stmt_bind_result($stmt, $row->id_m,
	  $row->idAppChar,
	  $row->idTargetState,
	  $row->idCaseCategorie,
	  $row->idLevImp);
      }

      mysqli_stmt_free_result($stmt);
      mysqli_close($this->connection);

      return $rows;
	
  }
  

  
  
  public function addTarSta ($item){
  
    $stmt = mysqli_prepare($this->connection,
        "CALL addTarSta (?)");
		
      $this->throwExceptionOnError();
          mysqli_stmt_bind_param($stmt, 's', $item);
      $this->throwExceptionOnError();
      mysqli_stmt_execute($stmt);
      $this->throwExceptionOnError();

      mysqli_stmt_free_result($stmt);
      mysqli_close($this->connection);
	  
  
  }
  
    public function deleteTarSta ($itemID){
  
    $stmt = mysqli_prepare($this->connection,
        "CALL deleteTarSta(?)");
		
      $this->throwExceptionOnError();
          mysqli_stmt_bind_param($stmt, 'i', $itemID);
      $this->throwExceptionOnError();
      mysqli_stmt_execute($stmt);
      $this->throwExceptionOnError();

      mysqli_stmt_free_result($stmt);
      mysqli_close($this->connection);
	  
  
  }
  
  public function updateTargetState ( $itemID, $itemName) {
	$stmt = mysqli_prepare($this->connection,
        "CALL updateTargetState(?,?)");
		
      $this->throwExceptionOnError();
          mysqli_stmt_bind_param($stmt, 'is', $itemID, $itemName);
      $this->throwExceptionOnError();
      mysqli_stmt_execute($stmt);
      $this->throwExceptionOnError();

      mysqli_stmt_free_result($stmt);
      mysqli_close($this->connection);
	}
	
	  public function searchMethodByClassification ( $idAppCha, 
													 $idTarSta,
													$idCasCat,
													$idCasCat2,
													$idCasCat3,
													$idCasCat4,
													$idCasCat5,
													$idCasCat6,
													$idLevImp) 
													{
	$stmt = mysqli_prepare($this->connection,
        "CALL searchMethodByIDClassification(?,?,?,?,?,?,?,?,?)");
		
      $this->throwExceptionOnError();
          mysqli_stmt_bind_param($stmt, 'iiiiiiiii', $idAppCha, 
													 $idTarSta,
													$idCasCat,
													$idCasCat2,
													$idCasCat3,
													$idCasCat4,
													$idCasCat5,
													$idCasCat6,
													$idLevImp);
      $this->throwExceptionOnError();
      mysqli_stmt_execute($stmt);
      $this->throwExceptionOnError();

      $rows = array();
      mysqli_stmt_bind_result($stmt, $row->id, $row->name);

      while (mysqli_stmt_fetch($stmt)) {
          $rows[] = $row;
          $row = new stdClass();
          mysqli_stmt_bind_result($stmt, $row->id, $row->name);
      }

      mysqli_stmt_free_result($stmt);
      mysqli_close($this->connection);

      return $rows;
	}
/** 
  * Utitity function to throw an exception if an error occurs 
  * while running a mysql command. 
  */ 
  private function throwExceptionOnError($link = null) { 
    if($link == null) { 
      $link = $this->connection; 
    } 
    if(mysqli_error($link)) { 
      $msg = mysqli_errno($link) . ": " . mysqli_error($link); 
      throw new Exception('MySQL Error - '. $msg); 
    }         
  } 
  
} 
?>
